import java.util.*;


public class Solution7 {
    public static void main(String[] args) {
        int[] nums={1,1,2};
        Solution7 s=new Solution7();
        List<List<Integer>> lists = s.permuteUnique(nums);
    }
    private List<List<Integer>> result = new ArrayList<>();
    int n;
    public List<List<Integer>> permuteUnique(int[] nums) {
        List<Integer> list = new ArrayList<Integer>();
        n = nums.length;
        for(int i=0;i<nums.length;i++){
            list.add(nums[i]);
        }
        _recurrent(0,list);
        return result;
    }
    private void _recurrent(int level,List<Integer> list){
        if(level == n){
            result.add(new ArrayList<>(list));
            return;
        }
        for(int i=level;i<n;i++){
            if(!isRepeact(list,level,i)){
                Collections.swap(list,level,i);
                _recurrent(level+1,list);
                Collections.swap(list,level,i);
            }
        }
    }
    private boolean isRepeact(List<Integer> list,int level,int i){
        int temp = list.get(i);
        for(int j = level;j<i;j++){
            if(list.get(j) == temp){
                return true;
            }
        }
        return false;
    }
}
